﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using PanicButtonLib;

namespace TestClientCSharp {

    public partial class TestClientForm: Form {

        private readonly IPanicButton panicButton;

        private void UpdateLidStatus( bool lidOpen ) {
            labelLidStatus.Text = lidOpen ? "OPEN" : "closed";
        }

        private void UpdateButtonStatus( bool buttonPressed ) {
            labelButtonStatus.Text = buttonPressed ? "PRESSED" : "up";
        }

        public TestClientForm( ) {
            InitializeComponent( );

            panicButton = new PanicButtonLib.PanicButton( );
            panicButton.OpenDevice( );

            var panicButtonEvents = (DPanicButtonEvents_Event) panicButton;
            panicButtonEvents.LidStatusChange += LidStatusChange;
            panicButtonEvents.ButtonStatusChange += ButtonStatusChange;
        }

        void LidStatusChange( bool lidOpen ) {
            if ( InvokeRequired ) {
                Invoke( (Action<bool>) UpdateLidStatus, lidOpen );
            } else {
                UpdateLidStatus( lidOpen );
            }
        }

        void ButtonStatusChange( bool buttonPressed ) {
            if ( InvokeRequired ) {
                Invoke( (Action<bool>) UpdateButtonStatus, buttonPressed );
            } else {
                UpdateButtonStatus( buttonPressed );
            }
        }

    }

}
